﻿using System;
using HoundSharp;


namespace shserver
{
    public class SignalHound
    {
        private static SignalHound _instance;

        public static SignalHound Instance
        {
            get
            {
                return _instance != null ? _instance : new SignalHound();
            }
        }

        public int init()
        {
            return SA44B_Device.SHAPI_Initialize();
        }

        public int configure(double attenVal = 10.0, int mixerBand = 1, int sensitivity = 0, int decimation = 1, int IF_Path = 0, int ADC_clock = 0)
        {
            return SA44B_Device.SHAPI_Configure(attenVal, mixerBand, sensitivity, decimation, IF_Path, ADC_clock);
        }

        public void getError(int code)
        {
            
        }

        public void reset()
        {
            SA44B_Device.SHAPI_CyclePowerOnExit();
        }


        public void demas()
        {
            double myStartFrequency = 248.91e6;
            double myStopFrequency = 249.09e6;
            int myFFTSize = 512; //50 KHz RBW
            int returnCount = 0;

            int count = SA44B_Device.SHAPI_GetSlowSweepCount(myStartFrequency, myStopFrequency, myFFTSize);
            double[] myTrace = new double[count + 4];

            for (int a = 0; a < 20; a++)
            {
                SA44B_Device.SHAPI_GetSlowSweep(myTrace, myStartFrequency, myStopFrequency, ref returnCount, myFFTSize, 2, 0);

                String myValStr = "";

                for (int i = 0; i < count; i++)
                {
                    myTrace[i] *= -1;
                    myValStr += myTrace[i].ToString() + ";";
                }
                Console.WriteLine(myValStr);
                //context.Send(myValStr);
            }
        }
    }
}